#include <stdio.h>
#include<string.h>
int main()
{
#if 0
    int val1 = 100;
    int val2 = 200;
    char sex = 'm';
    int val3 = 300;

    /*打印变量的地址*/
    printf("val1 = %p\n", &val1);
    printf("val2 = %p\n", &val2);
    printf("sex = %p\n", &sex);
    printf("val3 = %p\n", &val3);
#endif

#if 0
    /*数组的定义*/
    /*[]里表示有多少个元素*/
    int nums[8];
    /*数组的赋值*/
    nums[0] = 70;
    nums[1] = 123;
    nums[2] = 90;
    nums[3] = 97;
    nums[7] = 78;

    /*数组的取值*/
    printf ("nums[3] = %d\n",nums[3]);

    /*数组元素的地址*/
    for(int idx =0;idx < 8;idx++)
    {
        printf("&nums[%d] = %p\n",idx,&nums[idx]);
    }
    // printf("nums[0] = %p\n",&nums[0]);

    /*数组的内存*/
    int length = sizeof(nums);
    printf("length = %d\n",length);

    /*脏数据*/
    int array[10] = { 0 };
    for(int idx = 0;idx < 10;idx++)
    printf("array[%d] = %d\n",idx,array[idx]);

    /*数组的定义*/
    int infos[] = {12, 34, 17, 23, 9, 66, 42, 40};
    int size = sizeof(infos);
    printf("size = %d\n",size);
    int eleNum = sizeof(infos) / sizeof(int);
    printf("eleNum= %d\n",eleNum);
#endif

#if 0
    /*相同的数据类型*/
    /*整型数组*/
    int nums[5];

    /*赋值*/
    nums[0] = 12;
    nums[1] = 99.9996;
    nums[2] = 'c';

    printf("nums[1] = %d\n", nums[1]);

    /*字符数组*/
    char array[6] = {};

    /*赋值*/
    array[0] = 'h';
    array[1] = 'e';
    array[2] = 'l';
    array[3] = 'l';
    array[4] = 'o';

    /*取值*/
    for (int idx = 0; idx < 6; idx++)
    {
        printf("array[%d] = %c\n", idx, array[idx]);
    }

    /*内存*/
    int size = sizeof(array);
    printf("size = %d\n",size);

    /*地址*/
    for (int idx = 0; idx < 6; idx++)
    {
        printf("&array[%d] = %p\n", idx, &array[idx]);
    }
#endif

#if 0
int nums[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8,}, {9, 10, 11, 12}};

/*内存*/
int size = sizeof(nums);
printf("%d\n",size);

/*取值*/
for(int row = 0;row < 3;row++)
{
   for(int col = 0;col < 4;col++) 
   {
    printf("nums[%d][%d]=%d\t",row,col,nums[row][col]);
   }
   printf("\n");
}

#endif

#if 0
    /*地址*/
    int nums[5] = {12,13,21,7};
    printf("&num[0] = %p\n",&nums[0]);
    /*数组名到底是什么*/
    printf("nums = %p\n",nums);
    /*总结：数组名就是数组首元素地址*/

    nums[0]=666;
    /*数组名是地址，地址是常量，常量不能被改变*/
#endif

#if 0
    /*二维数组*/
    int array[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
    
    printf("&array[0][0] = %p\n",&array[0][0]);

    printf("array = %p\n",array);

    printf("array[0]=%p\n",array[0]);

    /*二维数组：数组名=数组第一行的地址=数组首元素地址*/
    printf("array[0]=%p\n",array[1]);
    printf("array[0]=%p\n",array[2]);

    /*总结：二维数组的邻行相差的内存地址取决于每一行的元素个数*/

   // array[0] + 1
   printf("array[0][1]=%p\n",&array[0][1]);
   printf("array[0]+1=%p\n",array[0]+1);
#endif

#if 1
    /*字符数组*/
    
#if 0
    /*这种定义方式不好*/
    buffer[0]='z';
#endif

#if 0
    /*以字符串的方式定义*/
    char buffer[]="Hello World Good!";

    // printf("buffer[0]= %c\n",buffer[0]);

    int len=sizeof(buffer)/sizeof(buffer[0]);

    for(int idx=0;idx<len;idx++)
    {
        if((buffer[idx] >= 'a')&&(buffer[idx] <= 'z'))
        {
            buffer[idx] -=32;
        }
    }
    printf("buffer[]=\"%s\"\n",buffer);
  
#endif

#if 1
    char buffer0[]={'C','L','a','s','s'};
    char buffer1[]={'H','e','l','l','o','W'};
    char buffer2[]="HelloW";
    /*总结：{'','',''}本身并不满意结束符，\0结束符*/
    int len1=sizeof(buffer1);
    int len2=sizeof(buffer2);
    int len3=strlen(buffer2);
    printf("%d\t%d\t%d\n",len1,len2,len3);

    printf("buffer0:%p\tbuffer0:%s\n",buffer0,buffer0);
    printf("buffer1:%p\tbuffer1:%s\n",buffer1,buffer1);
    printf("buffer2:%p\tbuffer2:%s\n",buffer2,buffer2);
#endif

#endif

return 0;
}